﻿Imports System.Data.SqlClient
Imports MySql.Data.MySqlClient

Public Class frmNAP_DAUKY_TonKhoHangHoa_Lo
    Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents btnNew As System.Windows.Forms.Button
    Friend WithEvents btnSave As System.Windows.Forms.Button
    Friend WithEvents btnDelete1 As System.Windows.Forms.Button
    Friend WithEvents txtTienCuoiKy As System.Windows.Forms.TextBox
    Friend WithEvents BtnClose As System.Windows.Forms.Button
    Friend WithEvents TxtHH As System.Windows.Forms.TextBox
    Friend WithEvents Label9 As System.Windows.Forms.Label
    Friend WithEvents DataGridView1 As System.Windows.Forms.DataGridView
    Friend WithEvents TentaikhoanDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents RecycleIDDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents MataikhoanDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents NodauvnDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents CodauvnDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents PsnovnDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents PscovnDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents LknovnDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents LkcovnDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents NocuoivnDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents CocuoivnDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents MakhachhangDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents ManhacungcapDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents PhatsinhnotrongkyDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents ThanhtoantrongkyDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents ThanhtiencuoikyDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents TxtSLCuoiky As System.Windows.Forms.TextBox
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents CboKho As MTGCComboBox
    Friend WithEvents TxtKho As System.Windows.Forms.TextBox
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents KhoDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents DataGridViewTextBoxColumn2 As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents TxtDVT As System.Windows.Forms.TextBox
    Friend WithEvents TxtSoLo As System.Windows.Forms.TextBox
    Friend WithEvents Label5 As System.Windows.Forms.Label
    Friend WithEvents Label6 As System.Windows.Forms.Label
    Friend WithEvents txtHSD As System.Windows.Forms.MaskedTextBox
    Friend WithEvents DPTHSD As System.Windows.Forms.DateTimePicker
    Friend WithEvents TbldotnhapxuattonghoploBindingSource As System.Windows.Forms.BindingSource
    Friend WithEvents DataSetNAP_DAUKY As PHUQUI.DataSetNAP_DAUKY
    Friend WithEvents colmahh As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents TenbietduocDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents DonvibanchanDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents SoluongdaukyDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents ThanhtiendaukyDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents SoluongnhaptrongkyDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents ThanhtiennhaptrongkyDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents SoluongxuattrongkyDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents ThanhtienxuattrongkyDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents SoluongcuoikyDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents DataGridViewTextBoxColumn1 As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents DataGridViewTextBoxColumn3 As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents colmakho As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents SoloDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents HandungDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents gridViewSearch1 As System.Windows.Forms.DataGridView
    Friend WithEvents TblsearchBindingSource As System.Windows.Forms.BindingSource
    Friend WithEvents DataSetSearch As PHUQUI.DataSetSearch
    Friend WithEvents Btn_Chuyen As System.Windows.Forms.Button
    Friend WithEvents ma As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents ten As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents CBoHH As MTGCComboBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(frmNAP_DAUKY_TonKhoHangHoa_Lo))
        Dim DataGridViewCellStyle1 As System.Windows.Forms.DataGridViewCellStyle = New System.Windows.Forms.DataGridViewCellStyle
        Dim DataGridViewCellStyle2 As System.Windows.Forms.DataGridViewCellStyle = New System.Windows.Forms.DataGridViewCellStyle
        Dim DataGridViewCellStyle3 As System.Windows.Forms.DataGridViewCellStyle = New System.Windows.Forms.DataGridViewCellStyle
        Dim DataGridViewCellStyle4 As System.Windows.Forms.DataGridViewCellStyle = New System.Windows.Forms.DataGridViewCellStyle
        Dim DataGridViewCellStyle5 As System.Windows.Forms.DataGridViewCellStyle = New System.Windows.Forms.DataGridViewCellStyle
        Dim DataGridViewCellStyle6 As System.Windows.Forms.DataGridViewCellStyle = New System.Windows.Forms.DataGridViewCellStyle
        Dim DataGridViewCellStyle7 As System.Windows.Forms.DataGridViewCellStyle = New System.Windows.Forms.DataGridViewCellStyle
        Dim DataGridViewCellStyle8 As System.Windows.Forms.DataGridViewCellStyle = New System.Windows.Forms.DataGridViewCellStyle
        Dim DataGridViewCellStyle9 As System.Windows.Forms.DataGridViewCellStyle = New System.Windows.Forms.DataGridViewCellStyle
        Dim DataGridViewCellStyle10 As System.Windows.Forms.DataGridViewCellStyle = New System.Windows.Forms.DataGridViewCellStyle
        Me.btnSave = New System.Windows.Forms.Button
        Me.txtTienCuoiKy = New System.Windows.Forms.TextBox
        Me.Label2 = New System.Windows.Forms.Label
        Me.Label1 = New System.Windows.Forms.Label
        Me.btnNew = New System.Windows.Forms.Button
        Me.btnDelete1 = New System.Windows.Forms.Button
        Me.BtnClose = New System.Windows.Forms.Button
        Me.TxtHH = New System.Windows.Forms.TextBox
        Me.Label9 = New System.Windows.Forms.Label
        Me.DataGridView1 = New System.Windows.Forms.DataGridView
        Me.colmahh = New System.Windows.Forms.DataGridViewTextBoxColumn
        Me.TenbietduocDataGridViewTextBoxColumn = New System.Windows.Forms.DataGridViewTextBoxColumn
        Me.DonvibanchanDataGridViewTextBoxColumn = New System.Windows.Forms.DataGridViewTextBoxColumn
        Me.SoluongdaukyDataGridViewTextBoxColumn = New System.Windows.Forms.DataGridViewTextBoxColumn
        Me.ThanhtiendaukyDataGridViewTextBoxColumn = New System.Windows.Forms.DataGridViewTextBoxColumn
        Me.SoluongnhaptrongkyDataGridViewTextBoxColumn = New System.Windows.Forms.DataGridViewTextBoxColumn
        Me.ThanhtiennhaptrongkyDataGridViewTextBoxColumn = New System.Windows.Forms.DataGridViewTextBoxColumn
        Me.SoluongxuattrongkyDataGridViewTextBoxColumn = New System.Windows.Forms.DataGridViewTextBoxColumn
        Me.ThanhtienxuattrongkyDataGridViewTextBoxColumn = New System.Windows.Forms.DataGridViewTextBoxColumn
        Me.SoluongcuoikyDataGridViewTextBoxColumn = New System.Windows.Forms.DataGridViewTextBoxColumn
        Me.DataGridViewTextBoxColumn1 = New System.Windows.Forms.DataGridViewTextBoxColumn
        Me.DataGridViewTextBoxColumn3 = New System.Windows.Forms.DataGridViewTextBoxColumn
        Me.colmakho = New System.Windows.Forms.DataGridViewTextBoxColumn
        Me.SoloDataGridViewTextBoxColumn = New System.Windows.Forms.DataGridViewTextBoxColumn
        Me.HandungDataGridViewTextBoxColumn = New System.Windows.Forms.DataGridViewTextBoxColumn
        Me.TbldotnhapxuattonghoploBindingSource = New System.Windows.Forms.BindingSource(Me.components)
        Me.DataSetNAP_DAUKY = New PHUQUI.DataSetNAP_DAUKY
        Me.CBoHH = New MTGCComboBox
        Me.TxtSLCuoiky = New System.Windows.Forms.TextBox
        Me.Label3 = New System.Windows.Forms.Label
        Me.CboKho = New MTGCComboBox
        Me.TxtKho = New System.Windows.Forms.TextBox
        Me.Label4 = New System.Windows.Forms.Label
        Me.TxtDVT = New System.Windows.Forms.TextBox
        Me.TxtSoLo = New System.Windows.Forms.TextBox
        Me.Label5 = New System.Windows.Forms.Label
        Me.Label6 = New System.Windows.Forms.Label
        Me.txtHSD = New System.Windows.Forms.MaskedTextBox
        Me.DPTHSD = New System.Windows.Forms.DateTimePicker
        Me.gridViewSearch1 = New System.Windows.Forms.DataGridView
        Me.TblsearchBindingSource = New System.Windows.Forms.BindingSource(Me.components)
        Me.DataSetSearch = New PHUQUI.DataSetSearch
        Me.Btn_Chuyen = New System.Windows.Forms.Button
        Me.ma = New System.Windows.Forms.DataGridViewTextBoxColumn
        Me.ten = New System.Windows.Forms.DataGridViewTextBoxColumn
        CType(Me.DataGridView1, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.TbldotnhapxuattonghoploBindingSource, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.DataSetNAP_DAUKY, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.gridViewSearch1, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.TblsearchBindingSource, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.DataSetSearch, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'btnSave
        '
        Me.btnSave.BackColor = System.Drawing.Color.Transparent
        Me.btnSave.Image = CType(resources.GetObject("btnSave.Image"), System.Drawing.Image)
        Me.btnSave.Location = New System.Drawing.Point(272, 175)
        Me.btnSave.Name = "btnSave"
        Me.btnSave.Size = New System.Drawing.Size(96, 24)
        Me.btnSave.TabIndex = 7
        Me.btnSave.UseVisualStyleBackColor = False
        '
        'txtTienCuoiKy
        '
        Me.txtTienCuoiKy.Font = New System.Drawing.Font("Arial", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.txtTienCuoiKy.Location = New System.Drawing.Point(432, 133)
        Me.txtTienCuoiKy.MaxLength = 100
        Me.txtTienCuoiKy.Name = "txtTienCuoiKy"
        Me.txtTienCuoiKy.Size = New System.Drawing.Size(144, 22)
        Me.txtTienCuoiKy.TabIndex = 6
        Me.txtTienCuoiKy.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(101, 132)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(84, 19)
        Me.Label2.TabIndex = 12
        Me.Label2.Text = "SL cuối kỳ"
        '
        'Label1
        '
        Me.Label1.BackColor = System.Drawing.Color.Transparent
        Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 15.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label1.ForeColor = System.Drawing.Color.Maroon
        Me.Label1.Location = New System.Drawing.Point(132, 9)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(507, 24)
        Me.Label1.TabIndex = 11
        Me.Label1.Text = "NẠP ĐẦU KỲ TỒN KHO HÀNG HÓA THEO LÔ"
        '
        'btnNew
        '
        Me.btnNew.Image = CType(resources.GetObject("btnNew.Image"), System.Drawing.Image)
        Me.btnNew.Location = New System.Drawing.Point(162, 175)
        Me.btnNew.Name = "btnNew"
        Me.btnNew.Size = New System.Drawing.Size(96, 24)
        Me.btnNew.TabIndex = 8
        '
        'btnDelete1
        '
        Me.btnDelete1.Image = CType(resources.GetObject("btnDelete1.Image"), System.Drawing.Image)
        Me.btnDelete1.Location = New System.Drawing.Point(382, 175)
        Me.btnDelete1.Name = "btnDelete1"
        Me.btnDelete1.Size = New System.Drawing.Size(88, 24)
        Me.btnDelete1.TabIndex = 29
        '
        'BtnClose
        '
        Me.BtnClose.Image = CType(resources.GetObject("BtnClose.Image"), System.Drawing.Image)
        Me.BtnClose.Location = New System.Drawing.Point(482, 175)
        Me.BtnClose.Name = "BtnClose"
        Me.BtnClose.Size = New System.Drawing.Size(88, 24)
        Me.BtnClose.TabIndex = 30
        '
        'TxtHH
        '
        Me.TxtHH.BackColor = System.Drawing.SystemColors.Window
        Me.TxtHH.Font = New System.Drawing.Font("Arial", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.TxtHH.Location = New System.Drawing.Point(339, 54)
        Me.TxtHH.MaxLength = 500
        Me.TxtHH.Name = "TxtHH"
        Me.TxtHH.Size = New System.Drawing.Size(238, 22)
        Me.TxtHH.TabIndex = 100
        '
        'Label9
        '
        Me.Label9.Location = New System.Drawing.Point(105, 54)
        Me.Label9.Name = "Label9"
        Me.Label9.Size = New System.Drawing.Size(81, 19)
        Me.Label9.TabIndex = 45
        Me.Label9.Text = "Mã hàng hóa"
        '
        'DataGridView1
        '
        Me.DataGridView1.AllowUserToAddRows = False
        Me.DataGridView1.AllowUserToDeleteRows = False
        Me.DataGridView1.AllowUserToResizeColumns = False
        Me.DataGridView1.AutoGenerateColumns = False
        Me.DataGridView1.BackgroundColor = System.Drawing.Color.LightBlue
        DataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter
        DataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Control
        DataGridViewCellStyle1.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        DataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.WindowText
        DataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight
        DataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText
        DataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.[True]
        Me.DataGridView1.ColumnHeadersDefaultCellStyle = DataGridViewCellStyle1
        Me.DataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize
        Me.DataGridView1.Columns.AddRange(New System.Windows.Forms.DataGridViewColumn() {Me.colmahh, Me.TenbietduocDataGridViewTextBoxColumn, Me.DonvibanchanDataGridViewTextBoxColumn, Me.SoluongdaukyDataGridViewTextBoxColumn, Me.ThanhtiendaukyDataGridViewTextBoxColumn, Me.SoluongnhaptrongkyDataGridViewTextBoxColumn, Me.ThanhtiennhaptrongkyDataGridViewTextBoxColumn, Me.SoluongxuattrongkyDataGridViewTextBoxColumn, Me.ThanhtienxuattrongkyDataGridViewTextBoxColumn, Me.SoluongcuoikyDataGridViewTextBoxColumn, Me.DataGridViewTextBoxColumn1, Me.DataGridViewTextBoxColumn3, Me.colmakho, Me.SoloDataGridViewTextBoxColumn, Me.HandungDataGridViewTextBoxColumn})
        Me.DataGridView1.DataSource = Me.TbldotnhapxuattonghoploBindingSource
        Me.DataGridView1.Location = New System.Drawing.Point(7, 217)
        Me.DataGridView1.Name = "DataGridView1"
        Me.DataGridView1.ReadOnly = True
        Me.DataGridView1.RowHeadersWidth = 20
        Me.DataGridView1.Size = New System.Drawing.Size(784, 344)
        Me.DataGridView1.TabIndex = 46
        '
        'colmahh
        '
        Me.colmahh.DataPropertyName = "ma_hanghoa"
        DataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter
        Me.colmahh.DefaultCellStyle = DataGridViewCellStyle2
        Me.colmahh.HeaderText = "Mã HH"
        Me.colmahh.Name = "colmahh"
        Me.colmahh.ReadOnly = True
        Me.colmahh.Width = 70
        '
        'TenbietduocDataGridViewTextBoxColumn
        '
        Me.TenbietduocDataGridViewTextBoxColumn.DataPropertyName = "ten_bietduoc"
        Me.TenbietduocDataGridViewTextBoxColumn.HeaderText = "Tên Hàng Hóa"
        Me.TenbietduocDataGridViewTextBoxColumn.Name = "TenbietduocDataGridViewTextBoxColumn"
        Me.TenbietduocDataGridViewTextBoxColumn.ReadOnly = True
        Me.TenbietduocDataGridViewTextBoxColumn.Width = 160
        '
        'DonvibanchanDataGridViewTextBoxColumn
        '
        Me.DonvibanchanDataGridViewTextBoxColumn.DataPropertyName = "donvi_banchan"
        DataGridViewCellStyle3.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter
        Me.DonvibanchanDataGridViewTextBoxColumn.DefaultCellStyle = DataGridViewCellStyle3
        Me.DonvibanchanDataGridViewTextBoxColumn.HeaderText = "ĐVT"
        Me.DonvibanchanDataGridViewTextBoxColumn.Name = "DonvibanchanDataGridViewTextBoxColumn"
        Me.DonvibanchanDataGridViewTextBoxColumn.ReadOnly = True
        Me.DonvibanchanDataGridViewTextBoxColumn.Width = 45
        '
        'SoluongdaukyDataGridViewTextBoxColumn
        '
        Me.SoluongdaukyDataGridViewTextBoxColumn.DataPropertyName = "soluong_dauky"
        Me.SoluongdaukyDataGridViewTextBoxColumn.HeaderText = "soluong_dauky"
        Me.SoluongdaukyDataGridViewTextBoxColumn.Name = "SoluongdaukyDataGridViewTextBoxColumn"
        Me.SoluongdaukyDataGridViewTextBoxColumn.ReadOnly = True
        Me.SoluongdaukyDataGridViewTextBoxColumn.Visible = False
        '
        'ThanhtiendaukyDataGridViewTextBoxColumn
        '
        Me.ThanhtiendaukyDataGridViewTextBoxColumn.DataPropertyName = "thanhtien_dauky"
        Me.ThanhtiendaukyDataGridViewTextBoxColumn.HeaderText = "thanhtien_dauky"
        Me.ThanhtiendaukyDataGridViewTextBoxColumn.Name = "ThanhtiendaukyDataGridViewTextBoxColumn"
        Me.ThanhtiendaukyDataGridViewTextBoxColumn.ReadOnly = True
        Me.ThanhtiendaukyDataGridViewTextBoxColumn.Visible = False
        '
        'SoluongnhaptrongkyDataGridViewTextBoxColumn
        '
        Me.SoluongnhaptrongkyDataGridViewTextBoxColumn.DataPropertyName = "soluongnhap_trongky"
        Me.SoluongnhaptrongkyDataGridViewTextBoxColumn.HeaderText = "soluongnhap_trongky"
        Me.SoluongnhaptrongkyDataGridViewTextBoxColumn.Name = "SoluongnhaptrongkyDataGridViewTextBoxColumn"
        Me.SoluongnhaptrongkyDataGridViewTextBoxColumn.ReadOnly = True
        Me.SoluongnhaptrongkyDataGridViewTextBoxColumn.Visible = False
        '
        'ThanhtiennhaptrongkyDataGridViewTextBoxColumn
        '
        Me.ThanhtiennhaptrongkyDataGridViewTextBoxColumn.DataPropertyName = "thanhtiennhap_trongky"
        Me.ThanhtiennhaptrongkyDataGridViewTextBoxColumn.HeaderText = "thanhtiennhap_trongky"
        Me.ThanhtiennhaptrongkyDataGridViewTextBoxColumn.Name = "ThanhtiennhaptrongkyDataGridViewTextBoxColumn"
        Me.ThanhtiennhaptrongkyDataGridViewTextBoxColumn.ReadOnly = True
        Me.ThanhtiennhaptrongkyDataGridViewTextBoxColumn.Visible = False
        '
        'SoluongxuattrongkyDataGridViewTextBoxColumn
        '
        Me.SoluongxuattrongkyDataGridViewTextBoxColumn.DataPropertyName = "soluongxuat_trongky"
        Me.SoluongxuattrongkyDataGridViewTextBoxColumn.HeaderText = "soluongxuat_trongky"
        Me.SoluongxuattrongkyDataGridViewTextBoxColumn.Name = "SoluongxuattrongkyDataGridViewTextBoxColumn"
        Me.SoluongxuattrongkyDataGridViewTextBoxColumn.ReadOnly = True
        Me.SoluongxuattrongkyDataGridViewTextBoxColumn.Visible = False
        '
        'ThanhtienxuattrongkyDataGridViewTextBoxColumn
        '
        Me.ThanhtienxuattrongkyDataGridViewTextBoxColumn.DataPropertyName = "thanhtienxuat_trongky"
        Me.ThanhtienxuattrongkyDataGridViewTextBoxColumn.HeaderText = "thanhtienxuat_trongky"
        Me.ThanhtienxuattrongkyDataGridViewTextBoxColumn.Name = "ThanhtienxuattrongkyDataGridViewTextBoxColumn"
        Me.ThanhtienxuattrongkyDataGridViewTextBoxColumn.ReadOnly = True
        Me.ThanhtienxuattrongkyDataGridViewTextBoxColumn.Visible = False
        '
        'SoluongcuoikyDataGridViewTextBoxColumn
        '
        Me.SoluongcuoikyDataGridViewTextBoxColumn.DataPropertyName = "soluongcuoiky"
        DataGridViewCellStyle4.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight
        DataGridViewCellStyle4.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        DataGridViewCellStyle4.Format = "N0"
        Me.SoluongcuoikyDataGridViewTextBoxColumn.DefaultCellStyle = DataGridViewCellStyle4
        Me.SoluongcuoikyDataGridViewTextBoxColumn.HeaderText = "SL CK"
        Me.SoluongcuoikyDataGridViewTextBoxColumn.Name = "SoluongcuoikyDataGridViewTextBoxColumn"
        Me.SoluongcuoikyDataGridViewTextBoxColumn.ReadOnly = True
        Me.SoluongcuoikyDataGridViewTextBoxColumn.Width = 80
        '
        'DataGridViewTextBoxColumn1
        '
        Me.DataGridViewTextBoxColumn1.DataPropertyName = "thanhtiencuoiky"
        DataGridViewCellStyle5.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight
        DataGridViewCellStyle5.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        DataGridViewCellStyle5.Format = "N0"
        Me.DataGridViewTextBoxColumn1.DefaultCellStyle = DataGridViewCellStyle5
        Me.DataGridViewTextBoxColumn1.HeaderText = "TT CK"
        Me.DataGridViewTextBoxColumn1.Name = "DataGridViewTextBoxColumn1"
        Me.DataGridViewTextBoxColumn1.ReadOnly = True
        '
        'DataGridViewTextBoxColumn3
        '
        Me.DataGridViewTextBoxColumn3.DataPropertyName = "recycleID"
        DataGridViewCellStyle6.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter
        Me.DataGridViewTextBoxColumn3.DefaultCellStyle = DataGridViewCellStyle6
        Me.DataGridViewTextBoxColumn3.HeaderText = "Tháng"
        Me.DataGridViewTextBoxColumn3.Name = "DataGridViewTextBoxColumn3"
        Me.DataGridViewTextBoxColumn3.ReadOnly = True
        Me.DataGridViewTextBoxColumn3.Width = 65
        '
        'colmakho
        '
        Me.colmakho.DataPropertyName = "makho"
        DataGridViewCellStyle7.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter
        Me.colmakho.DefaultCellStyle = DataGridViewCellStyle7
        Me.colmakho.HeaderText = "Kho"
        Me.colmakho.Name = "colmakho"
        Me.colmakho.ReadOnly = True
        Me.colmakho.Width = 55
        '
        'SoloDataGridViewTextBoxColumn
        '
        Me.SoloDataGridViewTextBoxColumn.DataPropertyName = "solo"
        DataGridViewCellStyle8.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight
        Me.SoloDataGridViewTextBoxColumn.DefaultCellStyle = DataGridViewCellStyle8
        Me.SoloDataGridViewTextBoxColumn.HeaderText = "Số Lô"
        Me.SoloDataGridViewTextBoxColumn.Name = "SoloDataGridViewTextBoxColumn"
        Me.SoloDataGridViewTextBoxColumn.ReadOnly = True
        Me.SoloDataGridViewTextBoxColumn.Width = 80
        '
        'HandungDataGridViewTextBoxColumn
        '
        Me.HandungDataGridViewTextBoxColumn.DataPropertyName = "handung"
        DataGridViewCellStyle9.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter
        Me.HandungDataGridViewTextBoxColumn.DefaultCellStyle = DataGridViewCellStyle9
        Me.HandungDataGridViewTextBoxColumn.HeaderText = "Hạn Dùng"
        Me.HandungDataGridViewTextBoxColumn.Name = "HandungDataGridViewTextBoxColumn"
        Me.HandungDataGridViewTextBoxColumn.ReadOnly = True
        Me.HandungDataGridViewTextBoxColumn.Width = 90
        '
        'TbldotnhapxuattonghoploBindingSource
        '
        Me.TbldotnhapxuattonghoploBindingSource.DataMember = "tbl_dot_nhapxuattonghop_lo"
        Me.TbldotnhapxuattonghoploBindingSource.DataSource = Me.DataSetNAP_DAUKY
        '
        'DataSetNAP_DAUKY
        '
        Me.DataSetNAP_DAUKY.DataSetName = "DataSetNAP_DAUKY"
        Me.DataSetNAP_DAUKY.SchemaSerializationMode = System.Data.SchemaSerializationMode.IncludeSchema
        '
        'CBoHH
        '
        Me.CBoHH.ArrowBoxColor = System.Drawing.SystemColors.Control
        Me.CBoHH.ArrowColor = System.Drawing.Color.Black
        Me.CBoHH.BindedControl = Nothing
        Me.CBoHH.BorderStyle = MTGCComboBox.TipiBordi.Fixed3D
        Me.CBoHH.CharacterCasing = System.Windows.Forms.CharacterCasing.Normal
        Me.CBoHH.ColumnNum = 1
        Me.CBoHH.ColumnWidth = "121"
        Me.CBoHH.DisabledArrowBoxColor = System.Drawing.SystemColors.Control
        Me.CBoHH.DisabledArrowColor = System.Drawing.Color.LightGray
        Me.CBoHH.DisabledBackColor = System.Drawing.SystemColors.Control
        Me.CBoHH.DisabledBorderColor = System.Drawing.SystemColors.InactiveBorder
        Me.CBoHH.DisabledForeColor = System.Drawing.SystemColors.GrayText
        Me.CBoHH.DisplayMember = "Text"
        Me.CBoHH.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed
        Me.CBoHH.DropDownBackColor = System.Drawing.Color.FromArgb(CType(CType(193, Byte), Integer), CType(CType(210, Byte), Integer), CType(CType(238, Byte), Integer))
        Me.CBoHH.DropDownForeColor = System.Drawing.Color.Black
        Me.CBoHH.DropDownStyle = MTGCComboBox.CustomDropDownStyle.DropDown
        Me.CBoHH.DropDownWidth = 141
        Me.CBoHH.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.CBoHH.GridLineColor = System.Drawing.Color.LightGray
        Me.CBoHH.GridLineHorizontal = False
        Me.CBoHH.GridLineVertical = False
        Me.CBoHH.LoadingType = MTGCComboBox.CaricamentoCombo.ComboBoxItem
        Me.CBoHH.Location = New System.Drawing.Point(192, 54)
        Me.CBoHH.ManagingFastMouseMoving = True
        Me.CBoHH.ManagingFastMouseMovingInterval = 30
        Me.CBoHH.Name = "CBoHH"
        Me.CBoHH.SelectedItem = Nothing
        Me.CBoHH.SelectedValue = Nothing
        Me.CBoHH.Size = New System.Drawing.Size(144, 23)
        Me.CBoHH.TabIndex = 1
        '
        'TxtSLCuoiky
        '
        Me.TxtSLCuoiky.Font = New System.Drawing.Font("Arial", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.TxtSLCuoiky.Location = New System.Drawing.Point(192, 133)
        Me.TxtSLCuoiky.MaxLength = 100
        Me.TxtSLCuoiky.Name = "TxtSLCuoiky"
        Me.TxtSLCuoiky.Size = New System.Drawing.Size(144, 22)
        Me.TxtSLCuoiky.TabIndex = 5
        Me.TxtSLCuoiky.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
        '
        'Label3
        '
        Me.Label3.Location = New System.Drawing.Point(342, 132)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(84, 19)
        Me.Label3.TabIndex = 102
        Me.Label3.Text = "Tiền cuối kỳ"
        '
        'CboKho
        '
        Me.CboKho.ArrowBoxColor = System.Drawing.SystemColors.Control
        Me.CboKho.ArrowColor = System.Drawing.Color.Black
        Me.CboKho.BindedControl = Nothing
        Me.CboKho.BorderStyle = MTGCComboBox.TipiBordi.Fixed3D
        Me.CboKho.CharacterCasing = System.Windows.Forms.CharacterCasing.Normal
        Me.CboKho.ColumnNum = 1
        Me.CboKho.ColumnWidth = "121"
        Me.CboKho.DisabledArrowBoxColor = System.Drawing.SystemColors.Control
        Me.CboKho.DisabledArrowColor = System.Drawing.Color.LightGray
        Me.CboKho.DisabledBackColor = System.Drawing.SystemColors.Control
        Me.CboKho.DisabledBorderColor = System.Drawing.SystemColors.InactiveBorder
        Me.CboKho.DisabledForeColor = System.Drawing.SystemColors.GrayText
        Me.CboKho.DisplayMember = "Text"
        Me.CboKho.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed
        Me.CboKho.DropDownBackColor = System.Drawing.Color.FromArgb(CType(CType(193, Byte), Integer), CType(CType(210, Byte), Integer), CType(CType(238, Byte), Integer))
        Me.CboKho.DropDownForeColor = System.Drawing.Color.Black
        Me.CboKho.DropDownStyle = MTGCComboBox.CustomDropDownStyle.DropDown
        Me.CboKho.DropDownWidth = 141
        Me.CboKho.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.CboKho.GridLineColor = System.Drawing.Color.LightGray
        Me.CboKho.GridLineHorizontal = False
        Me.CboKho.GridLineVertical = False
        Me.CboKho.LoadingType = MTGCComboBox.CaricamentoCombo.ComboBoxItem
        Me.CboKho.Location = New System.Drawing.Point(192, 81)
        Me.CboKho.ManagingFastMouseMoving = True
        Me.CboKho.ManagingFastMouseMovingInterval = 30
        Me.CboKho.Name = "CboKho"
        Me.CboKho.SelectedItem = Nothing
        Me.CboKho.SelectedValue = Nothing
        Me.CboKho.Size = New System.Drawing.Size(144, 23)
        Me.CboKho.TabIndex = 2
        '
        'TxtKho
        '
        Me.TxtKho.BackColor = System.Drawing.SystemColors.Window
        Me.TxtKho.Font = New System.Drawing.Font("Arial", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.TxtKho.Location = New System.Drawing.Point(339, 81)
        Me.TxtKho.MaxLength = 500
        Me.TxtKho.Name = "TxtKho"
        Me.TxtKho.ReadOnly = True
        Me.TxtKho.Size = New System.Drawing.Size(238, 22)
        Me.TxtKho.TabIndex = 105
        '
        'Label4
        '
        Me.Label4.Location = New System.Drawing.Point(102, 81)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(84, 19)
        Me.Label4.TabIndex = 104
        Me.Label4.Text = "Mã kho"
        '
        'TxtDVT
        '
        Me.TxtDVT.Font = New System.Drawing.Font("Arial", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.TxtDVT.Location = New System.Drawing.Point(583, 54)
        Me.TxtDVT.MaxLength = 500
        Me.TxtDVT.Name = "TxtDVT"
        Me.TxtDVT.Size = New System.Drawing.Size(86, 22)
        Me.TxtDVT.TabIndex = 106
        Me.TxtDVT.Visible = False
        '
        'TxtSoLo
        '
        Me.TxtSoLo.Font = New System.Drawing.Font("Arial", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.TxtSoLo.Location = New System.Drawing.Point(192, 108)
        Me.TxtSoLo.MaxLength = 100
        Me.TxtSoLo.Name = "TxtSoLo"
        Me.TxtSoLo.Size = New System.Drawing.Size(144, 22)
        Me.TxtSoLo.TabIndex = 3
        Me.TxtSoLo.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
        '
        'Label5
        '
        Me.Label5.Location = New System.Drawing.Point(342, 107)
        Me.Label5.Name = "Label5"
        Me.Label5.Size = New System.Drawing.Size(84, 19)
        Me.Label5.TabIndex = 110
        Me.Label5.Text = "Hạn dùng "
        '
        'Label6
        '
        Me.Label6.Location = New System.Drawing.Point(101, 107)
        Me.Label6.Name = "Label6"
        Me.Label6.Size = New System.Drawing.Size(84, 19)
        Me.Label6.TabIndex = 108
        Me.Label6.Text = "Số lô "
        '
        'txtHSD
        '
        Me.txtHSD.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.txtHSD.Location = New System.Drawing.Point(432, 108)
        Me.txtHSD.Mask = "00/00/0000"
        Me.txtHSD.Name = "txtHSD"
        Me.txtHSD.Size = New System.Drawing.Size(121, 20)
        Me.txtHSD.TabIndex = 4
        Me.txtHSD.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
        '
        'DPTHSD
        '
        Me.DPTHSD.CalendarFont = New System.Drawing.Font("Arial", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.DPTHSD.CustomFormat = "dd/MM/yyyy"
        Me.DPTHSD.Location = New System.Drawing.Point(554, 108)
        Me.DPTHSD.Name = "DPTHSD"
        Me.DPTHSD.Size = New System.Drawing.Size(21, 20)
        Me.DPTHSD.TabIndex = 1008
        '
        'gridViewSearch1
        '
        Me.gridViewSearch1.AllowUserToAddRows = False
        Me.gridViewSearch1.AllowUserToDeleteRows = False
        Me.gridViewSearch1.AllowUserToResizeColumns = False
        Me.gridViewSearch1.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.gridViewSearch1.AutoGenerateColumns = False
        Me.gridViewSearch1.AutoSizeRowsMode = System.Windows.Forms.DataGridViewAutoSizeRowsMode.AllCells
        Me.gridViewSearch1.BackgroundColor = System.Drawing.Color.LightBlue
        DataGridViewCellStyle10.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter
        DataGridViewCellStyle10.BackColor = System.Drawing.SystemColors.Control
        DataGridViewCellStyle10.Font = New System.Drawing.Font("Arial", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        DataGridViewCellStyle10.ForeColor = System.Drawing.SystemColors.WindowText
        DataGridViewCellStyle10.SelectionBackColor = System.Drawing.SystemColors.Highlight
        DataGridViewCellStyle10.SelectionForeColor = System.Drawing.SystemColors.HighlightText
        DataGridViewCellStyle10.WrapMode = System.Windows.Forms.DataGridViewTriState.[True]
        Me.gridViewSearch1.ColumnHeadersDefaultCellStyle = DataGridViewCellStyle10
        Me.gridViewSearch1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize
        Me.gridViewSearch1.Columns.AddRange(New System.Windows.Forms.DataGridViewColumn() {Me.ma, Me.ten})
        Me.gridViewSearch1.DataSource = Me.TblsearchBindingSource
        Me.gridViewSearch1.Location = New System.Drawing.Point(315, 77)
        Me.gridViewSearch1.Name = "gridViewSearch1"
        Me.gridViewSearch1.RowHeadersVisible = False
        Me.gridViewSearch1.Size = New System.Drawing.Size(465, 367)
        Me.gridViewSearch1.TabIndex = 1049
        '
        'TblsearchBindingSource
        '
        Me.TblsearchBindingSource.DataMember = "tbl_search"
        Me.TblsearchBindingSource.DataSource = Me.DataSetSearch
        '
        'DataSetSearch
        '
        Me.DataSetSearch.DataSetName = "DataSetSearch"
        Me.DataSetSearch.SchemaSerializationMode = System.Data.SchemaSerializationMode.IncludeSchema
        '
        'Btn_Chuyen
        '
        Me.Btn_Chuyen.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Btn_Chuyen.Location = New System.Drawing.Point(598, 175)
        Me.Btn_Chuyen.Name = "Btn_Chuyen"
        Me.Btn_Chuyen.Size = New System.Drawing.Size(182, 24)
        Me.Btn_Chuyen.TabIndex = 1050
        Me.Btn_Chuyen.Text = "Chuyển Sang Tồn Hàng Hóa"
        '
        'ma
        '
        Me.ma.DataPropertyName = "ma"
        Me.ma.HeaderText = "ma"
        Me.ma.Name = "ma"
        Me.ma.ReadOnly = True
        Me.ma.Width = 80
        '
        'ten
        '
        Me.ten.DataPropertyName = "ten"
        Me.ten.HeaderText = "ten"
        Me.ten.Name = "ten"
        Me.ten.ReadOnly = True
        Me.ten.Width = 360
        '
        'frmNAP_DAUKY_TonKhoHangHoa_Lo
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.BackColor = System.Drawing.Color.LightBlue
        Me.ClientSize = New System.Drawing.Size(792, 573)
        Me.Controls.Add(Me.gridViewSearch1)
        Me.Controls.Add(Me.DPTHSD)
        Me.Controls.Add(Me.txtHSD)
        Me.Controls.Add(Me.TxtSoLo)
        Me.Controls.Add(Me.Label5)
        Me.Controls.Add(Me.Label6)
        Me.Controls.Add(Me.TxtDVT)
        Me.Controls.Add(Me.CboKho)
        Me.Controls.Add(Me.TxtKho)
        Me.Controls.Add(Me.Label4)
        Me.Controls.Add(Me.TxtSLCuoiky)
        Me.Controls.Add(Me.Label3)
        Me.Controls.Add(Me.CBoHH)
        Me.Controls.Add(Me.DataGridView1)
        Me.Controls.Add(Me.TxtHH)
        Me.Controls.Add(Me.Label9)
        Me.Controls.Add(Me.BtnClose)
        Me.Controls.Add(Me.txtTienCuoiKy)
        Me.Controls.Add(Me.btnDelete1)
        Me.Controls.Add(Me.btnNew)
        Me.Controls.Add(Me.btnSave)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.Btn_Chuyen)
        Me.Name = "frmNAP_DAUKY_TonKhoHangHoa_Lo"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "NAP DAU KY"
        CType(Me.DataGridView1, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.TbldotnhapxuattonghoploBindingSource, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.DataSetNAP_DAUKY, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.gridViewSearch1, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.TblsearchBindingSource, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.DataSetSearch, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub

#End Region
    Private dataHangHoa, dataKho As DataTable
    Private da As MySqlDataAdapter
    Dim myDT, tmp As New DataTable
    Dim strError As String = ""
    Dim myform As Form
    Dim sqlQuery As String = ""
    Dim flag_s As Boolean = False
    Sub SetclearData()
        TxtSLCuoiky.Text = "0"
        txtTienCuoiKy.Text = "0"
        CBoHH.SelectedIndex = -1
        TxtHH.Text = ""
        'CboKho.Text = ""
        'TxtKho.Text = ""
        TxtSoLo.Text = ""
        txtHSD.Text = ""

    End Sub
    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        ' Kiểm tra có nhập liệu chưa ?
        If Me.checkInput() Then
            Dim txtMaTK = Me.CBoHH.Text.Trim
            Dim txtMaKho = Me.CboKho.Text.Trim


            sqlQuery = " SELECT ma_hanghoa FROM tbl_dot_nhapxuattonghop_Lo WHERE  recycleID='" & globalVariale.NAPDAUKY & "' "
            sqlQuery += " and ma_hanghoa = '" & txtMaTK & "' and makho = '" & txtMaKho & "'"
            sqlQuery += " and solo = '" & Me.TxtSoLo.Text.Trim & "' and handung = '" & Format(CDate(Me.txtHSD.Text.Trim), "yyyy-MM-dd") & "'"
            Dim existedMamon As Integer = moduleDatabaseConn.CheckRecordExisted(sqlQuery)
            If existedMamon = 1 Then ' Update record
                sqlQuery = "UPDATE tbl_dot_nhapxuattonghop_Lo "
                sqlQuery += "SET "
                sqlQuery += "ma_hanghoa = '" & txtMaTK & "'"
                sqlQuery += " ,ten_bietduoc = '" & Me.TxtHH.Text.Trim & "'"
                sqlQuery += " ,donvi_banchan = '" & Me.TxtDVT.Text.Trim & " '"
                sqlQuery += ", soluong_dauky = 0"
                sqlQuery += ", thanhtien_dauky = 0"
                sqlQuery += ", soluongnhap_trongky = 0"
                sqlQuery += ", thanhtiennhap_trongky = 0"
                sqlQuery += ", soluongxuat_trongky = 0"
                sqlQuery += ", thanhtienxuat_trongky = 0"
                sqlQuery += ", soluongcuoiky = '" & Replace(CDec(Me.TxtSLCuoiky.Text), ",", ".") & "'"
                sqlQuery += ", thanhtiencuoiky = '" & Replace(CDec(Me.txtTienCuoiKy.Text), ",", ".") & "'"
                sqlQuery += " ,recycleID = '" & globalVariale.NAPDAUKY & "'"
                sqlQuery += " ,makho = '" & Me.CboKho.Text.Trim & "'"
                sqlQuery += " ,solo = '" & Me.TxtSoLo.Text.Trim & "'"
                sqlQuery += " ,handung = '" & Format(CDate(Me.txtHSD.Text.Trim), "yyyy-MM-dd") & "'"
                sqlQuery += " WHERE  ma_hanghoa= '" & txtMaTK & "' "
                sqlQuery += " and recycleID='" & globalVariale.NAPDAUKY & "' "
                sqlQuery += " and makho= '" & txtMaKho & "' "
                sqlQuery += " and solo= '" & Me.TxtSoLo.Text.Trim & "' "
                sqlQuery += " and handung= '" & Format(CDate(Me.txtHSD.Text.Trim), "yyyy-MM-dd") & "'"
                Dim updated As Integer = moduleDatabaseConn.ExecuteNonQuery(sqlQuery)
                If updated = 1 Then
                    MessageBox.Show("Cập nhật thông tin thành công !")
                    sqlQuery = "SELECT * FROM tbl_dot_nhapxuattonghop_Lo where recycleID='" & globalVariale.NAPDAUKY & "' order by ma_hanghoa "
                    Me.loadCDTK(sqlQuery)
                Else
                    MessageBox.Show("Cập nhật thông tin không thành công: " & globalVariale.sqlMsgError)
                End If

            Else
                If existedMamon = 0 Then ' Insert record
                    sqlQuery = "INSERT INTO tbl_dot_nhapxuattonghop_Lo "
                    sqlQuery += "(ma_hanghoa,ten_bietduoc,donvi_banchan,soluong_dauky,thanhtien_dauky,soluongnhap_trongky,thanhtiennhap_trongky,soluongxuat_trongky,thanhtienxuat_trongky,soluongcuoiky,thanhtiencuoiky,recycleID,makho,solo,handung) "
                    sqlQuery += "VALUES "
                    sqlQuery += "("
                    sqlQuery += "'" & Me.CBoHH.Text.Trim & "', "
                    sqlQuery += "'" & Me.TxtHH.Text.Trim & "', "
                    sqlQuery += "'" & Me.TxtDVT.Text.Trim & "', "
                    sqlQuery += "0, "
                    sqlQuery += "0, "
                    sqlQuery += "0, "
                    sqlQuery += "0, "
                    sqlQuery += "0, "
                    sqlQuery += "0, "
                    sqlQuery += "'" & Replace(CDec(Me.TxtSLCuoiky.Text), ",", ".") & "', "
                    sqlQuery += "'" & Replace(CDec(Me.txtTienCuoiKy.Text), ",", ".") & "', "
                    sqlQuery += "'" & globalVariale.NAPDAUKY & "', "
                    sqlQuery += "'" & Me.CboKho.Text.Trim & "', "
                    sqlQuery += "'" & Me.TxtSoLo.Text.Trim & "', "
                    sqlQuery += "'" & Format(CDate(Me.txtHSD.Text.Trim), "yyyy-MM-dd") & "' "
                    sqlQuery += ")"
                    Dim inserted As Integer = moduleDatabaseConn.ExecuteNonQuery(sqlQuery)
                    If inserted = 1 Then
                        MessageBox.Show("Thêm thông tin thành công !")
                        sqlQuery = "SELECT * FROM tbl_dot_nhapxuattonghop_Lo where recycleID='" & globalVariale.NAPDAUKY & "' order by ma_hanghoa "
                        Me.loadCDTK(sqlQuery)
                    Else
                        MessageBox.Show("Thêm thông tin không thành công: " & globalVariale.sqlMsgError)
                    End If
                Else ' SQLExeption: existedMaQuocGia = -1
                    MessageBox.Show("Lấy dữ liệu bị lỗi: " & globalVariale.sqlMsgError, "Lấy dữ liệu", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                End If
            End If
        End If


    End Sub
    Private Sub btnNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNew.Click
        SetclearData()
        CBoHH.Focus()
    End Sub
    Private Sub btnDelete1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete1.Click
        Try
            Dim iRow As Integer = Me.DataGridView1.CurrentRow.Index
            Dim vmahh As String = Me.DataGridView1.Item(Me.colmahh.Index, iRow).Value
            Me.TxtSoLo.Text = Me.DataGridView1.Item(13, iRow).Value
            moduleConstants.MessageWarning = "Bạn có muốn xóa " & vmahh & " ?"
            If MessageBox.Show(moduleConstants.MessageWarning, globalVariale.msgTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = MsgBoxResult.Yes Then
                Dim sqlQuery As String = "DELETE FROM tbl_dot_nhapxuattonghop_Lo WHERE recycleID='" & globalVariale.NAPDAUKY & "' and ma_hanghoa = '" & vmahh & "' and makho = '" & Me.CboKho.Text.Trim & "' and solo = '" & Me.TxtSoLo.Text & "' "
                Dim deleting As Integer = moduleDatabaseConn.ExecuteNonQuery(sqlQuery)
                If deleting = 1 Then
                    MessageBox.Show("Xóa thông tin thành công !")
                    sqlQuery = "SELECT * FROM tbl_dot_nhapxuattonghop_Lo where recycleID='" & globalVariale.NAPDAUKY & "'order by ma_hanghoa "
                    Me.loadCDTK(sqlQuery)
                    SetclearData()
                Else
                    MessageBox.Show("Xóa thông tin không thành công: " & globalVariale.sqlMsgError)
                End If
            End If
        Catch ex As Exception

        End Try


        'If Me.TxtHH.Text = "" Then
        '    'If Me.CBoHH.SelectedItem.Col1 = "" Then
        '    MessageBox.Show("Bạn chưa chọn Mã để xóa !")
        'Else
        '    Dim txtTentk As String = Trim(Me.TxtHH.Text)
        '    moduleConstants.MessageWarning = "Bạn có muốn xóa " & Me.CBoHH.Text & "(" & txtTentk & ") ?"
        '    If MessageBox.Show(moduleConstants.MessageWarning, globalVariale.msgTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = MsgBoxResult.Yes Then
        '        Dim sqlQuery As String = "DELETE FROM tbl_dot_nhapxuattonghop_Lo WHERE recycleID='" & globalVariale.NAPDAUKY & "' and ma_hanghoa = '" & Me.CBoHH.Text.Trim & "' and makho = '" & Me.CboKho.Text.Trim & "'"
        '        Dim deleting As Integer = moduleDatabaseConn.ExecuteNonQuery(sqlQuery)
        '        If deleting = 1 Then
        '            MessageBox.Show("Xóa thông tin thành công !")
        '            sqlQuery = "SELECT * FROM tbl_dot_nhapxuattonghop_Lo where recycleID='" & globalVariale.NAPDAUKY & "'"
        '            Me.loadCDTK(sqlQuery)
        '            SetclearData()
        '        Else
        '            MessageBox.Show("Xóa thông tin không thành công: " & globalVariale.sqlMsgError)
        '        End If
        '    End If
        'End If
    End Sub
    Private Sub frmNAP_DAUKY_TonKhoHangHoa_Lo_load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        moduleUtils.setDinhDangVietNam()
        Me.loadDanhSachHH()
        Me.loadDanhSachKho()
        Me.loadCDTK("SELECT * FROM tbl_dot_nhapxuattonghop_Lo where recycleID='201101' order by ma_hanghoa ")
        SetclearData()
        Me.gridViewSearch1.Visible = False
        'flag_s = True

    End Sub

    Private Sub BtnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnClose.Click
        Me.Close()
    End Sub
    Private Function checkInput() As Boolean
        If Me.CBoHH.Text = "" Then
            MessageBox.Show("Bạn phải chọn mã!")
            Me.CBoHH.Focus()
            Return False
            Exit Function
        End If
        If IsNumeric(Me.TxtSLCuoiky.Text) = False Then
            MessageBox.Show("Bạn phải nhập số lượng là kiểu số !")
            Me.TxtSLCuoiky.Focus()
            Return False
            Exit Function
        End If
        If IsNumeric(Me.txtTienCuoiKy.Text) = False Then
            MessageBox.Show("Bạn phải nhập số lượng là kiểu số !")
            Me.txtTienCuoiKy.Focus()
            Return False
            Exit Function
        End If
        If Me.TxtSLCuoiky.Text = "0" And Me.txtTienCuoiKy.Text = "0" Then
            MessageBox.Show("Bạn phải nhập dữ liệu !")
            Me.TxtSLCuoiky.Focus()
            Return False
            Exit Function
        End If
        Return True
    End Function
    Private Sub loadCDTK(ByVal sqlQuery As String)
        'sqlQuery = "SELECT * FROM tbl_dot_nhapxuattonghop_lo where recycleid = '" & globalVariale.THANG_KHOIHANH & "'"
        Me.DataGridView1.DataSource = moduleDatabaseConn.GetDataTable(sqlQuery)
    End Sub
    Private Sub loadDanhSachHH()
        Try
            Dim sqlQuery As String = ""
            sqlQuery = "SELECT ma_hanghoa as ma , ten_bietduoc as ten ,donvi_banchan FROM tbl_hanghoa ORDER BY ma_hanghoa "
            dataHangHoa = moduleDatabaseConn.GetDataTable(sqlQuery)
            CBoHH.Items.Clear()
            CBoHH.LoadingType = MTGCComboBox.CaricamentoCombo.DataTable
            CBoHH.ColumnNum = 3
            CBoHH.ColumnWidth = "100;250;80"
            CBoHH.HighlightBorderColor = Color.Black
            CBoHH.GridLineHorizontal = True
            CBoHH.GridLineVertical = True
            CBoHH.ItemHeight = 17
            CBoHH.DropDownHeight = 300
            CBoHH.SourceDataTable = dataHangHoa
            CBoHH.SelectedIndex = 0
        Catch ex As Exception

        End Try

    End Sub
    Private Sub loadDanhSachKho()
        Try
            Dim sqlQuery As String = ""
            sqlQuery = "SELECT ma_kho, ten_kho FROM tbl_kho ORDER BY ma_kho"
            dataKho = moduleDatabaseConn.GetDataTable(sqlQuery)
            CboKho.Items.Clear()
            CboKho.LoadingType = MTGCComboBox.CaricamentoCombo.DataTable
            CboKho.ColumnNum = 2
            CboKho.ColumnWidth = "100;250"
            CboKho.HighlightBorderColor = Color.Black
            CboKho.GridLineHorizontal = True
            CboKho.GridLineVertical = True
            CboKho.ItemHeight = 17
            CboKho.DropDownHeight = 300
            CboKho.SourceDataTable = dataKho
            CboKho.SelectedIndex = 1
        Catch ex As Exception

        End Try

    End Sub
    Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
        Me.gridViewSearch1.Visible = False
        Try
            Dim iRow As Integer = Me.DataGridView1.CurrentRow.Index
            Me.TxtSLCuoiky.Text = Format(CDbl(Me.DataGridView1.Item(9, iRow).Value), "N0")
            Me.txtTienCuoiKy.Text = Format(CDbl(Me.DataGridView1.Item(10, iRow).Value), "N0")
            Me.TxtSoLo.Text = Me.DataGridView1.Item(13, iRow).Value
            Me.txtHSD.Text = Me.DataGridView1.Item(14, iRow).Value
            moduleUtils.setIndexComBo(Me.DataGridView1.Item(Me.colmahh.Index, iRow).Value, Me.CBoHH, dataHangHoa)
            moduleUtils.setIndexComBo(Me.DataGridView1.Item(Me.colmakho.Index, iRow).Value, Me.CboKho, dataKho)
        Catch ex As Exception
        End Try
    End Sub

    Private Sub CBoHH_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles CBoHH.MouseClick
        Me.gridViewSearch1.Visible = False
        flag_s = True

    End Sub

    Private Sub CBoHH_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CBoHH.SelectedIndexChanged
        Try
            Me.gridViewSearch1.Visible = False
            flag_s = True
            Dim vtien, Vsoluong As Double
            Dim vsolo, Vhandung, vmakho, ssolo, shandung As String

            Dim iRow As Integer = Me.DataGridView1.CurrentRow.Index
            ssolo = Me.DataGridView1.Item(13, iRow).Value.ToString
            shandung = Me.DataGridView1.Item(14, iRow).Value.ToString
            Try
                Me.TxtHH.Text = Me.CBoHH.SelectedItem.Col2
                Me.TxtDVT.Text = Me.CBoHH.SelectedItem.Col3
                '(soluongcuoiky,thanhtiencuoiky,recycleID,makho,solo,handung) "
                sqlQuery = "select soluongcuoiky,thanhtiencuoiky,makho,solo,handung from tbl_dot_nhapxuattonghop_Lo where  "
                sqlQuery += " solo='" & ssolo & "'  and recycleID='" & globalVariale.NAPDAUKY & "' and ma_hanghoa='" & Me.CBoHH.Text.Trim & "'"
                tmp = moduleDatabaseConn.GetDataTable(sqlQuery)
                If tmp.Rows.Count > 0 Then
                    Vsoluong = tmp.Rows.Item(0).Item(0)
                    vtien = tmp.Rows.Item(0).Item(1)
                    vmakho = tmp.Rows.Item(0).Item(2)
                    vsolo = tmp.Rows.Item(0).Item(3)
                    Vhandung = tmp.Rows.Item(0).Item(4)
                Else
                    vtien = 0
                    Vsoluong = 0
                    vmakho = ""
                    vsolo = ""
                    Vhandung = ""
                End If
                Me.TxtSLCuoiky.Text = Format(Vsoluong, "N0")
                Me.txtTienCuoiKy.Text = Format(vtien, "N0")
                Me.TxtSoLo.Text = vsolo
                Me.CboKho.Text = vmakho
                Me.txtHSD.Text = Vhandung
            Catch ex As Exception
            End Try
        Catch ex As Exception

        End Try
    End Sub

    Private Sub CboKho_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CboKho.SelectedIndexChanged
        Try
            Me.TxtKho.Text = Me.CboKho.SelectedItem.Col2
        Catch ex As Exception
        End Try
    End Sub
    Private Sub DPTHSD_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DPTHSD.ValueChanged
        Me.txtHSD.Text = Me.DPTHSD.Value
    End Sub
    Private Sub TxtHH_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TxtHH.MouseClick
        Me.TxtHH.Text = " "
        Me.gridViewSearch1.Visible = True
        flag_s = False
    End Sub
    Private Sub TxtHH_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TxtHH.TextChanged
        If flag_s = True Then
            Me.gridViewSearch1.Visible = False
        Else
            Me.gridViewSearch1.Visible = True
            Dim view As DataView = New DataView(dataHangHoa)
            view.RowFilter = " ma like '%" & Me.TxtHH.Text.Trim & "%' or ten like '%" & Me.TxtHH.Text.Trim & "%' "
            Me.gridViewSearch1.DataSource = view
        End If
    End Sub
    Private Sub gridViewSearch1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles gridViewSearch1.CellClick
        Dim row1 As Integer = Me.gridViewSearch1.CurrentRow.Index
        moduleUtils.setIndexComBo(Me.gridViewSearch1.Item(Me.ma.Index, row1).Value, Me.CBoHH, dataHangHoa)
        Me.TxtHH.Text = CBoHH.SelectedItem.Col2
        Me.gridViewSearch1.Visible = False
        flag_s = True
    End Sub
    Private Sub CBoHH_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CBoHH.TextChanged
        Me.gridViewSearch1.Visible = False
        flag_s = True
    End Sub

    Private Sub Btn_Chuyen_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Btn_Chuyen.Click
        Try
            If MessageBox.Show("Bạn có muốn chuyển Tồn Hàng hóa theo Lô sang Tồn Hàng hóa tổng hợp không ?,Cẩn thận số liệu Tồn Hàng hóa tổng hợp sẽ bị đè !! ", globalVariale.msgTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = MsgBoxResult.Yes Then
                Me.Cursor = Cursors.WaitCursor
                sqlQuery = "DELETE FROM tbl_dot_nhapxuattonghop WHERE recycleID = '201101'"
                moduleDatabaseConn.ExecuteNonQuery(sqlQuery)
                sqlQuery = "insert into tbl_dot_nhapxuattonghop (ma_hanghoa ,ten_bietduoc,donvi_banchan,soluongcuoiky,thanhtiencuoiky,recycleid,makho)"
                sqlQuery += " select ma_hanghoa ,ten_bietduoc,donvi_banchan,sum(soluongcuoiky),sum(thanhtiencuoiky),'201101',makho"
                sqlQuery += " from tbl_dot_nhapxuattonghop_lo where recycleid = '201101'group by ma_hanghoa;"
                moduleDatabaseConn.ExecuteNonQuery(sqlQuery)
                Me.Cursor = Cursors.Default
                MessageBox.Show("Đã chuyển Tồng Hàng hóa theo lô sang Tồng Hàng hóa Tổng hợp thành công !", globalVariale.msgTitle, MessageBoxButtons.OK, MessageBoxIcon.Information)
            End If
        Catch ex As Exception
        End Try
    End Sub
End Class


